package com.ruoyi.web.controller.reptilebytime;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.reptilebytime.domain.Reptile;
import com.ruoyi.reptilebytime.service.IReptileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 定时爬虫Controller
 * 
 * @author ruoyi
 * @date 2024-06-08
 */
@RestController
@RequestMapping("/reptilebytime/reptile")
public class ReptileController extends BaseController
{
    @Autowired
    private IReptileService reptileService;

    /**
     * 查询定时爬虫列表
     */
    @PreAuthorize("@ss.hasPermi('reptilebytime:reptile:list')")
    @GetMapping("/list")
    public TableDataInfo list(Reptile reptile)
    {
        startPage();
        List<Reptile> list = reptileService.selectReptileList(reptile);
        return getDataTable(list);
    }

    /**
     * 导出定时爬虫列表
     */
    @PreAuthorize("@ss.hasPermi('reptilebytime:reptile:export')")
    @Log(title = "定时爬虫", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reptile reptile)
    {
        List<Reptile> list = reptileService.selectReptileList(reptile);
        ExcelUtil<Reptile> util = new ExcelUtil<Reptile>(Reptile.class);
        util.exportExcel(response, list, "定时爬虫数据");
    }

    /**
     * 获取定时爬虫详细信息
     */
    @PreAuthorize("@ss.hasPermi('reptilebytime:reptile:query')")
    @GetMapping(value = "/{rId}")
    public AjaxResult getInfo(@PathVariable("rId") Long rId)
    {
        return success(reptileService.selectReptileByRId(rId));
    }

    /**
     * 新增定时爬虫
     */
    @PreAuthorize("@ss.hasPermi('reptilebytime:reptile:add')")
    @Log(title = "定时爬虫", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reptile reptile)
    {
        return toAjax(reptileService.insertReptile(reptile));
    }

    /**
     * 修改定时爬虫
     */
    @PreAuthorize("@ss.hasPermi('reptilebytime:reptile:edit')")
    @Log(title = "定时爬虫", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reptile reptile)
    {
        return toAjax(reptileService.updateReptile(reptile));
    }

    /**
     * 删除定时爬虫
     */
    @PreAuthorize("@ss.hasPermi('reptilebytime:reptile:remove')")
    @Log(title = "定时爬虫", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rIds}")
    public AjaxResult remove(@PathVariable Long[] rIds)
    {
        return toAjax(reptileService.deleteReptileByRIds(rIds));
    }
}
